<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set value="${pageContext.request.contextPath}" var="path"></c:set>
<link rel="stylesheet" type="text/css" href="${path}/static/web/css/AddStyle.css"/>
<html>
<head>
    <title>车辆登记</title>
</head>
<body>
<script type="text/javascript" src="${path}/static/web/js/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
    $(function (){
        $("#myform").submit(check);
    });

    function check()
    {
        var fcarname=checkCarname();

        return fcarname;
    }
</script>
<%--  验证车牌号  --%>
    <script type="text/javascript">
        $(function(){
        $("#carname").blur(checkCarname);
    });

        function checkCarname()
        {
            var carname = $("#carname").val();
            var reg = /^[\u4e00-\u9fa5][A-Z]\.[\dA-Z]{5,6}$/;
            var flag = reg.test(carname);
            if(flag==true)
        {

            var flag;
            $.ajax({
            url:"/project/web/CheckRenameController",
            data:"x="+carname,
            async:false,//同步
            type:"post",
            success:function(mes){
            if(mes=="true")
        {
            $("#carnameRs").css("color","green");
            $("#carnameRs").html("√");
            flag = true;
        }
            else
        {
            $("#carnameRs").css("color","red");
            $("#carnameRs").html("x重复");
            flag = false;
        }
        }
        });
            return flag;
        }
            else
        {
            $("#carnameRs").css("color","red");
            $("#carnameRs").html("x非法");
            return false;
        }
        }
</script>

    <!--添加车辆-->
    <form action="${path}/web/addCarName" method="post" class="Form" id="myform">
        <input type="hidden" name="user.id" value="${sessionScope.user.id}">
        <table style=" margin:50px auto;">
            <tbody>
            <tr><td> 车牌号:</td><td>  <input name="License" placeholder="请输入车牌号(例：鲁A.11111)" id="carname" style="width: 250px"><span id="carnameRs"></span></td></tr>
           <tr><td></td><td> <input type="submit" value="添加"  class="btnSure"></td></tr>
            </tbody>
        </table>
    </form>

</body>
</html>
